11 typedef map
<node
, vector
<node
> > graph
;
14 const color WHITE
= 0, GRAY
= 1, BLACK
= 2;
17 map
<node
, color
> colors
;
19 set
<node
> dfs(node v
, set
<node
> visited
, const node
& ignore
){
21 vector
<node
> neighbors
= g
[v
];
23 for (int i
=0; i
<neighbors
.size(); ++i
){
24 if (visited
.count(neighbors
[i
]) == 0 && neighbors
[i
] != ignore
){
25 set
<node
> temp
= dfs(neighbors
[i
], visited
, ignore
);
27 for (set
<node
>::iterator j
= temp
.begin(); j
!= temp
.end(); ++j
){
40 while (cin
>> n
&& n
> 0){
41 if (map
> 1) cout
<< endl
;
48 g
[v
] = vector
<node
>();
61 for (graph::iterator i
= g
.begin(); i
!= g
.end(); ++i
){
62 if (colors
[(*i
).first
] == WHITE
){
64 full
= dfs((*i
).first
, full
, "");
65 if (full
.size() == 1) continue;
66 for (set
<node
>::iterator j
= full
.begin(); j
!= full
.end(); ++j
){
67 set
<node
>::iterator initial
= full
.begin();
68 while ((*j
) == (*initial
)) ++initial
;
69 set
<node
> temp
= dfs((*initial
), set
<node
>(), (*j
));
70 if (temp
.size() + 1 < full
.size()){ //El +1 es por el nodo que ignoré
71 cameras
.push_back(*j
);
78 sort(cameras
.begin(), cameras
.end());
79 cout
<< "City map #"<<map
<<": " << cameras
.size() << " camera(s) found" << endl
;
80 copy(cameras
.begin(), cameras
.end(), ostream_iterator
<node
>(cout
,"\n"));